<?php


namespace app\erp\model;


use think\Model;

class Qingkuandb extends Model
{
    protected $pk = 'id';
    protected $name = 'qingkuan';

    public $append = ['qiantai_txt', 'bili_txt'];

    public $param = array();

    public function getQiantaiTxtAttr($val, $row)
    {
        $arr = ['无效订单', '待确认', '待发货', '待支付', '待收货', '已完成', '已退货', '已取消', '待妥投', '已废止'];
        return $arr[$row['qiantai']];
    }

    public function getBiliTxtAttr($val, $row)
    {
        return ($row['bili'] * 100) . '%';
    }


    public function base($query)
    {
        if (isset($this->param['out_order_no']) && $this->param['out_order_no']) {
            $query->where('out_order_no', $this->param['out_order_no']);
        }
        if (isset($this->param['bili']) && $this->param['bili']) {
            $query->where('bili', $this->param['bili'] / 100);
        }
        if (isset($this->param['gongyingshang']) && $this->param['gongyingshang']) {
            $query->where('gongyingshang', $this->param['gongyingshang']);
        }
        if (isset($this->param['huikuan']) && $this->param['huikuan'] != '') {
            $query->where('huikuan', $this->param['huikuan']);
        }
        if (isset($this->param['ruku']) && $this->param['ruku']) {
            $query->where('ruku', $this->param['ruku']);
        }
        if (isset($this->param['zhuangtai']) && $this->param['zhuangtai']) {
            $query->where('zhuangtai', $this->param['zhuangtai']);
        }
        if (isset($this->param['zizhi']) && $this->param['zizhi'] != '') {
            $query->where('zizhi', $this->param['zizhi']);
        }
        if (isset($this->param['pici_state']) && $this->param['pici_state']) {
            $query->where('pici_state', $this->param['pici_state']);
        }
        if (isset($this->param['pici']) && $this->param['pici']) {
            $query->where('pici','>=', str_replace('-', '/', $this->param['pici']));
        }
        if(isset($this->param['pici_end']) && $this->param['pici_end']){
            $query->where('pici','<=', str_replace('-', '/', $this->param['pici_end']));
        }
    }
}